﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ToDoList.Entity.Models;

namespace NewToDoList.logic
{
    public class OperateList
    {
        private static todoContext _ctx = new todoContext();
        public bool CreatDetailedList(string listName, int userId)
        {
            var user = _ctx.Users.SingleOrDefault(a => a.UserId == userId);
            if (user != null)
            {
                //_ctx.DetailedList.Add(
                //    new DetailedList { CreatTime = DateTime.Now, NameOfList = listName });
                user.DetailedList = new List<DetailedList>();
                user.DetailedList.Add(
                    new DetailedList { CreatTime = DateTime.Now, NameOfList = listName });
                return true;
            }
            else
                return false;
        }

        public bool ModifyListName(int listId, string newListName)
        {
            var list = _ctx.DetailedList.SingleOrDefault(a => a.ListId == listId);
            if (list != null)
            {
                list.NameOfList = newListName;

                return true;
            }
            else
                return false;
        }

        public List<DetailedList> ViewAllDetailedList(int uerId)
        {
            var user = _ctx.DetailedList.Where(a => a.UserId == uerId);
            if (user != null)
            {
                return user.ToList();
            }
            else
                return null;
        }
    }
}
